package com.hssy.wululuaplan.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hssy.wululuaplan.entity.ClassRemain;
import com.hssy.wululuaplan.mapper.ClassRemainMapper;
import com.hssy.wululuaplan.service.ClassRemainService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 课时结余情况 服务实现类
 * </p>
 *
 * @author Mr.Hongtao
 * @since 2024-02-28
 */
@Service
public class ClassRemainServiceImpl extends ServiceImpl<ClassRemainMapper, ClassRemain> implements ClassRemainService {

    @Override
    public ClassRemain findByStudentId(Integer studentId) {
        ClassRemain classRemain = baseMapper.selectOne(Wrappers.<ClassRemain>lambdaQuery()
                .eq(ClassRemain::getStudentId, studentId)
                .last("limit 1"));
        if (classRemain == null) {
            classRemain = new ClassRemain();
            classRemain.setStudentId(studentId);
            classRemain.setTotal(0);
            classRemain.setRemain(0);
            classRemain.setFree(0);
        }
        return classRemain;
    }
}
